/*
 * Copyright 2001-2009 www.jrj.com. All rights reserved. JRJ
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.hezuti.common.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 李井会
 * @version 1.0
 * @create Dec 16, 2009
 */
public class TextParseUtil {
    
    @SuppressWarnings("unchecked")
    public static Map parseText(String textUrl) {
        URL url;
        try {
            url = new URL(textUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            if (conn.getResponseCode() == 200) {
                return readBigCostContents(conn);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
    private static HashMap readBigCostContents(HttpURLConnection connection) throws IOException {
        BufferedReader in = null;
        HashMap stockMap = new HashMap();
        try {
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                String[] hq = inputLine.split("=");
                if (hq != null && hq.length == 2){
                    stockMap.put(hq[0], hq[1]);
                }                
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            in.close();
        }
        return stockMap;
    }
    
    public static void main(String[] args) {
        // parseText("http://jy.share.jrj.com.cn/flow/bigtoday.txt");
        // parseText("http://jy.share.jrj.com.cn/flow/costzone.txt");
        // System.out.println(ddr);
    }
}
